package repository

import (
	"rustdesk_api_server/global"
	"rustdesk_api_server/models"
)

var Peers = new(PeerRepository)

type PeerRepository struct{}

func (peer *PeerRepository) DeleteAll(user models.User) error {
	return global.DB.Where("user_id = ?", user.ID).Delete(&models.Peer{}).Error
}

func (peer *PeerRepository) Updates(peers []models.Peer) error {
	return global.DB.Create(peers).Error
}

func (peer *PeerRepository) GetByUserId(user_id uint) []models.Peer {
	var peers []models.Peer
	err := global.DB.Find(&peers, "user_id = ?", user_id).Error
	if err != nil {
		return nil
	} else {
		return peers
	}
}
